@extends('admin.pop_edit')
@section('body')
    <style>
        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            margin-left: 130px;
        }

        #diseaseContainer .layui-badge {
            margin: 5px;
            height: 26px;
            line-height: 26px;
        }

        #diseaseContainer a {
            color: red;
        }
    </style>
    <form lay-filter="editForm" action="{{admin_url($baseRoute.'update')}}" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-row">
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">咨询状态:</label>
                    <div class="layui-input-block">
                        <x-code code="AB" name="consultation_type"></x-code>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">挂号人姓名:</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" placeholder="请输入挂号人姓名"
                               class="layui-input"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">年龄:</label>
                    <div class="layui-input-block">
                        <input type="number" name="age" placeholder="请输入年龄" class="layui-input"/>
                    </div>
                </div>
            </div>
{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">真实姓名:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <input type="text" name="real_name" placeholder="请输入真实姓名" class="layui-input"/>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}

            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">下次回访时间:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hf_time"  readonly="true" id="txtHfTime" placeholder="请选择下次回访时间"
                               class="layui-input icon-date"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">性别:</label>
                    <div class="layui-input-block">
                        <x-code code="AA" name="gender" value="3" view="radio"></x-code>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">联系电话:</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" onblur="checkMobile(this)" placeholder="请输入联系电话"
                               class="layui-input"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">微信码:</label>
                    <div class="layui-input-block">
                        <input type="text" name="weixin" onblur="checkWeixin(this)" placeholder="请输入微信号"
                               class="layui-input"/>
                    </div>
                </div>
            </div>

{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">QQ号码:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <input type="text" name="qq" placeholder="请输入QQ号码" class="layui-input"/>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}
{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">座机号码:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <input type="text" name="phone" placeholder="请输入座机号码" class="layui-input"/>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">预约时间:</label>
                    <div class="layui-input-block">
                        <input type="text" name="yy_time" readonly="true" id="txtYyTime" placeholder="请输入预约时间"
                               class="layui-input icon-date"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">来源媒体:</label>
                    <div class="layui-input-block">
                        <x-ca.source name="source_id"></x-ca.source>
                    </div>
                </div>
            </div>

{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">预约方式:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <x-ca.consultation-way name="consultation_way_id"></x-ca.consultation-way>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}
{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">话务员:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <x-system.user name="medical_id" show-all="--选择话务员--"--}}
{{--                                       group="{{\App\Models\System\Group::CALLER}}"></x-system.user>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">医生:</label>
                    <div class="layui-input-block">
                        <x-ca.doctor name="yy_doctor_id" show-all="--选择挂号医生--"></x-ca.doctor>
                    </div>
                </div>
            </div>
{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">咨询客服:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        {{\App\Facade\AppContext::userInfo('name')}}--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}

            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">科室:</label>
                    <div class="layui-input-block">
                        <x-ca.top-disease show-all="--请选择科室--" id="sltTopDisease"
                                          lay-filter="topDisease"></x-ca.top-disease>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">疾病:</label>
                    <div style="float: right;">
                        <a type="button" onclick="addDisease()" class="layui-btn">添加</a>
                    </div>
                    <div class="layui-input-inline">
                        <select class="layui-input" id="sltDisease">

                        </select>
                    </div>

                </div>
            </div>
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">客户疾病:</label>
                    <div class="layui-input-block" id="diseaseContainer">
                        @empty($entity['disease_data'])
                        @else
                            @foreach($entity['disease_data'] as $disease)
                                <span data-id="{{$disease['id']}}" class="layui-badge layui-bg-blue">
                                    <input value="{{$disease['id']}}" type="hidden" name="diseases[]"/>{{$disease['name']}}&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="removeDisease(this)" title="移除"><i
                                                class="layui-icon layui-icon-close"></i></a>
                                </span>
                            @endforeach
                        @endempty
                    </div>
                </div>
            </div>

            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属省份:</label>
                    <div class="layui-input-block">
                        <x-system.province show-all="--请选择省份--" id="sltProvince" name="province_id"
                                           lay-filter="province"></x-system.province>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">所在市区:</label>
                    <div class="layui-input-block">
                        <select class="layui-input" id="sltCity" name="city_id">

                        </select>
                    </div>
                </div>
            </div>
{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">详细地址:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <input type="text" name="address" placeholder="请输入预约时间" class="layui-input"/>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}
{{--            <div class="layui-col-xs3">--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label">发病时间:</label>--}}
{{--                    <div class="layui-input-block">--}}
{{--                        <input type="text" name="fb_time" id="txtFbTime" placeholder="请输入发病时间"--}}
{{--                               class="layui-input icon-date"/>--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--            </div>--}}

            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">费用:</label>
                    <div class="layui-input-block">
                        <input type="text" name="cost_money" placeholder="请输入费用" class="layui-input"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">来源网站:</label>
                    <div class="layui-input-block">
                        <input type="text" name="source_site" placeholder="请输入来源网站" class="layui-input"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">IP地址:</label>
                    <div class="layui-input-block">
                        <input type="text" name="source_ip" placeholder="请输入IP地址" class="layui-input"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">状态:</label>
                    <div class="layui-input-block">
                        <x-code name="status" show-all="0" code="AC" value="1"></x-code>
                    </div>
                </div>
            </div>

            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">成永久身份ID:</label>
                    <div class="layui-input-block">
                        <input type="text" name="source_consulting_page" placeholder="请输入成永久身份ID"
                               class="layui-input"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">搜索关键词:</label>
                    <div class="layui-input-block">
                        <input type="text" name="source_search_keywords" placeholder="请输入搜索关键词"
                               class="layui-input"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <label class="layui-form-label">购买词:</label>
                    <div class="layui-input-block">
                        <input type="text" name="gm_words" placeholder="请输入购买词" class="layui-input"/>
                    </div>
                </div>
            </div>
        </div>

{{--        <div class="layui-form-item">--}}
{{--            <label class="layui-form-label">就诊史:</label>--}}
{{--            <div class="layui-input-block">--}}
{{--                <textarea placeholder="请输入就诊史" name="medical_history" class="layui-textarea"></textarea>--}}
{{--            </div>--}}
{{--        </div>--}}
        <div class="layui-form-item">
            <label class="layui-form-label">病情描述:</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入病情描述" name="disease_desc" class="layui-textarea"></textarea>
            </div>
        </div>
        {{--        <div class="layui-form-item">--}}
        {{--            <label class="layui-form-label">商务通信息识别:</label>--}}
        {{--            <div class="layui-input-block">--}}
        {{--                <textarea placeholder="请输入商务通信息识别" name="disease_desc" class="layui-textarea"></textarea>--}}
        {{--            </div>--}}
        {{--        </div>--}}
{{--        <div class="layui-form-item">--}}
{{--            <label class="layui-form-label">其他备注:</label>--}}
{{--            <div class="layui-input-block">--}}
{{--                <textarea placeholder="请输入其他备注" name="remark" class="layui-textarea"></textarea>--}}
{{--            </div>--}}
{{--        </div>--}}
        <div class="layui-form-item">
            <label class="layui-form-label">商务通记录:</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" placeholder="请输入商务通记录" id="txtContent" name="swt"></textarea>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="ajaxForm" lay-submit>@lang('common.save')</button>
            <button class="layui-btn layui-btn-primary" type="button"
                    ew-event="closeDialog">@lang('common.cancel')</button>
        </div>
    </form>
@stop
@push('script')
    <script type="text/javascript">
        let id = {{$entity['id']}};
        layui.use('form', function () {
            layui.form.val('editForm', {!! json_encode($entity) !!});
            layui.form.on('select(jump_type)', function (item) {
                jump_type_change(item.value);
            });

            layui.form.on('select(province)', function (item) {
                loadCity(item.value);
            });

            layui.form.on('select(topDisease)', function (item) {
                loadDisease(item.value);
            });

            function jump_type_change(value) {
                layui.$('.object_item').hide();
                layui.$('.object_item_' + value).show();
            }

            function loadDisease(value) {
                if (value) {
                    SystemUtil.ajax("{{admin_url('ca/disease/load')}}", "GET")
                        .setData({pid: value})
                        .send(1)
                        .done(function (res) {
                            let html = "<option value='0'>--请选择疾病--</option>";
                            res.data.forEach(function (item) {
                                html += `<option value='${item.id}'>${item.name}</option>`;
                            });
                            layui.$('#sltDisease').html(html);
                            layui.form.render("select");
                        });
                } else {
                    let html = "<option value='0'>--请选择疾病--</option>";
                    layui.$('#sltDisease').html(html);
                    layui.form.render("select");
                }
            }

            function loadCity(value) {
                if (value > 0) {
                    SystemUtil.ajax("{{admin_url('system/area/load')}}", "GET")
                        .setData({pid: value})
                        .send(1)
                        .done(function (res) {
                            let html = "<option value='0'>--请选择城市--</option>";
                            res.data.forEach(function (item) {
                                html += `<option value='${item.id}'>${item.name}</option>`;
                            });
                            layui.$('#sltCity').html(html);
                            layui.$('#sltCity').val({{$entity['city_id']}});
                            layui.form.render("select");
                        });
                } else {
                    let html = "<option value='0'>--请选择城市-</option>";
                    layui.$('#sltCity').html(html);
                    layui.form.render("select");
                }
            }

            loadCity(layui.$('#sltProvince').val());
            jump_type_change(1);
        });
        //
        layui.use(['form', 'admin', 'layedit', 'laydate'], function () {
            let laydate = layui.laydate;
            var txtIntroIndex = layui.layedit.build('txtContent', {
                uploadImage: {
                    url: "{{admin_url('/file/editerImage')}}",
                    data: {obj: 1},
                    type: 'post'
                }
            });
            laydate.render({
                elem: '#txtYyTime',
                type: 'datetime',
                trigger: 'click'
            });
            laydate.render({
                elem: '#txtHfTime',
                type: 'datetime',
                trigger: 'click'
            });

            layui.$('button[lay-filter="ajaxForm"]').mouseenter(function () {
                layui.layedit.sync(txtIntroIndex);
            });

            layui.$('button[lay-submit]').not('button[lay-filter="ajaxForm"]').mouseenter(function () {
                layui.layedit.sync(txtIntroIndex);
            });
        });

        function removeDisease(that) {
            layui.$(that).parent().remove();
        }

        function checkMobile(ele) {
            if (ele.value.length > 0)
                SystemUtil.ajax("{{admin_url($baseRoute.'check-mobile')}}", "GET").setData({mobile: ele.value}).send(1).then(res => {
                    if (res.data) {
                        layer.msg("客户手机号已存在！");
                    }
                });
        }

        function checkWeixin(ele) {
            if (ele.value.length > 0)
                SystemUtil.ajax("{{admin_url($baseRoute.'check-weixin')}}", "GET").setData({weixin: ele.value}).send(1).then(res => {
                    if (res.data) {
                        layer.msg("客户微信已存在！");
                    }
                });
        }


        function addDisease() {
            let diseaseId = layui.$('#sltDisease').val();
            if (diseaseId) {
                let diseaseName = layui.$('#sltDisease option:selected').text();
                let ids = [];
                layui.$('#diseaseContainer .layui-badge').each(function (i, el) {
                    ids.push(parseInt(layui.$(el).data('id')));
                });
                if (ids.indexOf(parseInt(diseaseId)) === -1) {
                    layui.$('#diseaseContainer').append(`<span data-id="${diseaseId}" class="layui-badge layui-bg-blue"><input value="${diseaseId}" type="hidden" name="diseases[]"/>${diseaseName}&nbsp;&nbsp;<a href="javascript:;" onclick="removeDisease(this)" title="移除"><i class="layui-icon layui-icon-close"></i></a></span>`);
                }

            } else {
                layer.msg('请选择疾病');
            }
        }
    </script>
@endpush